package cn.jiyun.interceptor;

import cn.jiyun.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        System.out.println("LoginInterceptord 的perhandle 执行了");
//log.debug("LoginInterceptord 的perhandle 执行了");
//        //登录状态校验
//        User user= (User) request.getSession().getAttribute("user");
//        if (user!=null){
//            return true;
//        }
//        return false;

        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
//        System.out.println("LoginInterceptord postHandle 执行了");
        log.debug("LoginInterceptord postHandle 执行了");

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//        System.out.println("LoginInterceptord afterCompletion 执行了");
        log.debug("LoginInterceptord afterCompletion 执行了");
    }
}
